export const platformList = [
  { code: "ebay", type1: "请选择承运人", type2: "" },
  {
    code: "amazon",
    type1: "请选择承运人",
    type2: "请选择配送服务",
  },
  {
    code: "otto",
    type1: "请选择发货承运商",
    type2: "请选择退货承运商",
  },
  {
    code: "walmart",
    type1: "请选择承运人",
    type2: "tracking Url",
  },
  {
    code: "shopify",
    type1: "请选择承运人",
    type2: "tracking Url",
  },
  {
    code: "rakuten",
    type1: "请选择承运人",
    type2: "",
  },
  {
    code: "temu",
    type1: "请选择国家",  //根据国家选择承运人
    type2: "请选择承运人",
  },
  {
    code: "shein_settled_in",
    type1: "请选择物流公司",
    type2: "",
    country:"country"   //单独国家
  },
  // { code: "shein_supplier", type1: "", type2: "" },
  { code: "shein_b", type1: "请选择物流公司", type2: "" , country:"country"},
  {
    code: "temu_b",
    type1: "请选择国家",
    type2: "请选择承运人",
  },
  {
    code: "kaufland",
    type1: "请选择承运人",
    type2: "",
  },
  { code: "others", type1: "", type2: "" },
  { code: "tik_tok", type1: "请选择承运人", type2: "" },
  { code: "aliexpress_b", type1: "请选择承运人", type2: "请选择配送服务", },
  { code: "aliexpress", type1: "请选择承运人" },
];

export function transformData(data) {
  const grouped = {};

  data.forEach((item) => {
    const { platform_code, country_code, carrier_code } = item;

    if (!grouped[platform_code]) {
      grouped[platform_code] = {
        ...item,
        country_codes: [],
        carrier_codes: {},
      };
    }

    if (country_code) {
      grouped[platform_code].country_codes.push({
        label: country_code,
        value: country_code,
      });
      // grouped[platform_code].carrier_codes.push({
      //   [country_code]: carrier_code,
      // });
      grouped[platform_code].carrier_codes[country_code] = carrier_code;
    } else {
      grouped[platform_code].carrier_code = carrier_code;
    }
  });

  return Object.values(grouped).map((item) => {
    if (item.country_codes.length === 0) {
      delete item.country_codes;
      delete item.carrier_codes;
    }
    return item;
  });
}
